using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Services;
using Sudoku.Lang;

namespace Sudoku.Menu
{
	public class OptionsScene : ExtendedGameComponent
	{
		Texture2D bg;
		Rectangle bgPos;
		Color bgColor;


		string message;
		SpriteFont messageFont;
		Vector2 messagePos;
		Color messageColor;

		IInputManager inputService;

		bool goBack;

		public OptionsScene(Game game)
			: base(game)
		{

		}

		public override void Initialize()
		{
			inputService = Game.Services.GetService(typeof(IInputManager)) as IInputManager;
			inputService.OnBack += new InputManager.PhoneButtonEvent(Back);

			bg = textureService.Background("General");
			bgPos = new Rectangle(0, 0, 480, 800);
			bgColor = Color.White;
			
			//MESSAGE
			messageFont = fontService.Font(FontType.DeliciousSmallCaps22);
			message = LocalizedStrings.EndMessageWin;
			messagePos = new Vector2(240 - (messageFont.MeasureString(message).X * 0.5f), 750);
			messageColor = new Color(0, 102, 153);

			soundService.TurnPageSound();

			goBack = false;

			base.Initialize();
		}

		protected override void Dispose(bool disposing)
		{
			inputService.OnBack -= new InputManager.PhoneButtonEvent(Back);

			base.Dispose(disposing);
		}

		private void Back()
		{
			goBack = true;
		}

		public override void Update(GameTime gameTime)
		{
			if (goBack)
			{
				soundService.PlaySound(SoundType.Fumble);
				StateManagement.StateManager.StartMenu(Game);
			}
			
			base.Update(gameTime);
		}

		public override void Draw(GameTime gameTime)
		{

			spriteBatch.Begin();

			spriteBatch.Draw(bg, bgPos, bgColor);
			spriteBatch.DrawString(messageFont, message, messagePos, messageColor);

			spriteBatch.End();

			base.Draw(gameTime);
		}
	}
}
